﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc。@Copy Right 2019
// 文件： GcWarnWord.cs
// 项目名称：斑马车务
// 创建时间：2019/11/7
// 负责人：lsc
// ===================================================================
using System;
using System.Data;
using System.Collections.Generic;
using Dapper.Extensions;
using YouWei.Infrastructure.Entity;
using YouWei.Infrastructure.Repository;
namespace YouWei.Infrastructure.Service
{
	
	/// <summary>
	///
	/// </summary>
	public class GcWarnWordService
	{
         protected GcWarnWordRepository repository;
         
         public  GcWarnWordService(){
           repository = new GcWarnWordRepository();         
         }
         
        #region 增删改查

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(GcWarnWord entity) { return repository.Insert(entity); }

        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public object Insert(List<GcWarnWord> entitys) { return repository.Insert(entitys); }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Update(GcWarnWord entity) { return repository.Update(entity); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public bool Delete(GcWarnWord entity) { return repository.Delete(entity); }

        /// <summary>
        /// 删除所有
        /// </summary>
        /// <returns></returns>
        public bool DeleteAll() { return repository.DeleteAll(); }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public bool Delete(int primaryKey) { return repository.Delete(primaryKey); }

        /// <summary>
        /// 查询单个实体
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public GcWarnWord SingleOrDefault(object primaryKey) { return repository.SingleOrDefault(primaryKey); }

       
        /// <summary>
        /// 查询单个实体,如果存在多条则引发异常
        /// </summary>
        /// <param name="primaryKey">主键</param>
        /// <returns></returns>
        public GcWarnWord Single(object primaryKey) { return repository.Single(primaryKey); }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<GcWarnWord> QueryAll()
        {
            return repository.QueryAll();
        }

        #endregion

        /// <summary>
        /// 获取预警敏感词
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, List<GcWarnWord>> GetWarnWordGroup()
        {
            Dictionary<int, List<GcWarnWord>> dic = new Dictionary<int, List<GcWarnWord>>();
            List< GcWarnWord > warnList = null;
            List<GcWarnWord> list = repository.QueryAll();
            foreach (var item in list)
            {
                if (!dic.ContainsKey(item.RuleID))
                {
                    warnList = new List<GcWarnWord>();
                    warnList.Add(item);
                    dic.Add(item.RuleID, warnList);
                }
                else {
                    warnList = dic[item.RuleID];
                    warnList.Add(item);
                    dic[item.RuleID] = warnList;
                }
            }
            return dic;
        }
	}
	
}